﻿/*****************************************************************
 *@Copyright all rights reserved © 2014 Yuga
 *@author YUga studio
 *Contact: zengkang007@gmail.com
 *****************************************************************/
package com.oplink.webbase.modules.invoicing.service;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.oplink.webbase.common.persistence.Page;
import com.oplink.webbase.modules.invoicing.entity.GoodsReturnDetail;
import com.oplink.webbase.modules.invoicing.dao.GoodsReturnDetailDao;



/**
 * 告警Service
 * @author YUga studio
 * @version 2015-01-12
 */
@Component
@Transactional
public class GoodsReturnDetailService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(GoodsReturnDetailService.class);
	
	@Autowired
	private GoodsReturnDetailDao goodsReturnDetailDao;
	
	public GoodsReturnDetail get(Long id) {
		return goodsReturnDetailDao.findOne(id);
	}
	
	public Page<GoodsReturnDetail> find(Page<GoodsReturnDetail> page, GoodsReturnDetail goodsReturnDetail) {
		DetachedCriteria dc = goodsReturnDetailDao.createDetachedCriteria();
		//添加查询条件
		if (null != goodsReturnDetail.getGoodsId()
				&& StringUtils.isNotEmpty(goodsReturnDetail.getGoodsId().toString())) {
			dc.add(Restrictions.like("goodsId", "%"+goodsReturnDetail.getGoodsId()+"%"));
		}
		if (null != goodsReturnDetail.getGoodsAmount()
				&& StringUtils.isNotEmpty(goodsReturnDetail.getGoodsAmount().toString())) {
			dc.add(Restrictions.like("goodsAmount", "%"+goodsReturnDetail.getGoodsAmount()+"%"));
		}
        if (StringUtils.isNotEmpty(goodsReturnDetail.getReason())){
			dc.add(Restrictions.like("reason", "%"+goodsReturnDetail.getReason()+"%"));
		}
		dc.add(Restrictions.eq(GoodsReturnDetail.DEL_FLAG, GoodsReturnDetail.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return goodsReturnDetailDao.find(page, dc);
	}
	
	/**
	  * @function 创建查询
	  **/
	public Page<GoodsReturnDetail> getUserGoodsReturnDetail(Page<GoodsReturnDetail> page, GoodsReturnDetail goodsReturnDetail) {
		DetachedCriteria dc = goodsReturnDetailDao.createDetachedCriteria();
		//添加查询条件
		if (null != goodsReturnDetail.getGoodsId()
				&& StringUtils.isNotEmpty(goodsReturnDetail.getGoodsId().toString())) {
			dc.add(Restrictions.like("goodsId", "%"+goodsReturnDetail.getGoodsId()+"%"));
		}
		if (null != goodsReturnDetail.getGoodsAmount()
				&& StringUtils.isNotEmpty(goodsReturnDetail.getGoodsAmount().toString())) {
			dc.add(Restrictions.like("goodsAmount", "%"+goodsReturnDetail.getGoodsAmount()+"%"));
		}
        if (StringUtils.isNotEmpty(goodsReturnDetail.getReason())){
			dc.add(Restrictions.like("reason", "%"+goodsReturnDetail.getReason()+"%"));
		}
		dc.add(Restrictions.eq(GoodsReturnDetail.DEL_FLAG, GoodsReturnDetail.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return goodsReturnDetailDao.find(page, dc);
	}
	
	public GoodsReturnDetail getGoodsReturnDetail(Long id) {
		return goodsReturnDetailDao.findOne(id);
	}

	public void saveGoodsReturnDetail(GoodsReturnDetail entity) {
		goodsReturnDetailDao.save(entity);
	}
	
	public void deleteGoodsReturnDetail(Long id) {
		goodsReturnDetailDao.delete(id);
	}
	
	@Autowired
	public void setGoodsReturnDetailDao(GoodsReturnDetailDao goodsReturnDetailDao) {
		this.goodsReturnDetailDao = goodsReturnDetailDao;
	}	
}
